package com.gibs.peixunapi.dao;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import com.gibs.peixunapi.model.LoginInfo;

@Repository
public interface LoginInfoDao extends JpaRepository<LoginInfo, Integer>, JpaSpecificationExecutor<LoginInfo> {

	@Query("from LoginInfo where UserId = ?1")
	List<LoginInfo> find(String name);

	@Query("from LoginInfo where UserId like ?1")
	List<LoginInfo> findLike(String name);

	@Query(value = "select * from LoginInfo limit ?, ?", nativeQuery = true)
	List<LoginInfo> findPage(Integer offset, Integer size);

	@Query(value = "select * from LoginInfo where UserId = ? limit ?, ?", nativeQuery = true)
	List<LoginInfo> findPage(String name, Integer offset, Integer size);

	@Query(value = "select * from LoginInfo where UserId like ? limit ?, ?", nativeQuery = true)
	List<LoginInfo> findPageLike(String name, Integer offset, Integer size);

	@Query(value = "select count(*) from LoginInfo where UserId = ?", nativeQuery = true)
	Long count(String name);

	@Query(value = "select count(*) from LoginInfo where UserId like ?", nativeQuery = true)
	Long countLike(String name);
	
	@Query("from LoginInfo order by id asc")
	List<LoginInfo> findAllAsc();
}

